﻿using System;
using System.Data;
using System.Data.SqlClient;
using Evaluation3.utils;

namespace Evaluation3.services
{
	/// <summary>
	/// Summary description for companyServices.
	/// </summary>
	public class companyServices
	{
		public companyServices()
		{

            #region Create default values for variables 
            sTenThietBi = "";
            sNamSanXuat = DateTime.Now.Year.ToString();
            sNoiSanXuat = "";
            sNangSuat = "";
            iLacHau = 0;
            iMaDoanhNghiep = 0;
            sMyImage = "";
            iMaThietBi = 0;
            #endregion
		}

        #region TungLA's Coded
        
        #region Define Variables
        string sTenThietBi;
        string sNamSanXuat;
        string sNoiSanXuat;
        string sNangSuat;
        int iLacHau;
        int iMaDoanhNghiep;
        string sMyImage;
        int iMaThietBi;

        string sqlStr;
        SqlParameter[] parr;
        #endregion

        #region Properties
        public string TenThietBi{get {return sTenThietBi;} set{sTenThietBi = value;}}
        public string NamSanXuat{get{return sNamSanXuat;} set {sNamSanXuat = value;}}
        public string NoiSanXuat{get {return sNoiSanXuat;} set {sNoiSanXuat = value;}}
        public string NangSuat {get {return sNangSuat;} set {sNangSuat = value;}}
        public int LacHau {get {return iLacHau;} set{iLacHau = value;}}
        public int MaDoanhNghiep {get {return iMaDoanhNghiep;} set {iMaDoanhNghiep = value;}}
        public string MyImage { get { return sMyImage; } set { sMyImage = value; } }
        public int MaThietBi { get { return iMaThietBi; } set { iMaThietBi = value; } }
        #endregion

        #region Methods

        #region DN_NewEquipment()
        /// <summary>
        /// Tùng La 15-06-2007
        /// Method thực hiện việc thêm mới một thiết bị cho doanh nghiệp
        /// </summary>
        public void DN_NewEquipment()
        {
            sqlStr = "TaoMoiThietBi_PROC";
            parr = new SqlParameter[7];
            parr[0] = new SqlParameter("@TenThietBi", SqlDbType.NVarChar, 100);
            parr[0].Value = TenThietBi;
            parr[1] = new SqlParameter("@NamSanXuat", SqlDbType.VarChar, 4);
            parr[1].Value = NamSanXuat;
            parr[2] = new SqlParameter("@NoiSanXuat", SqlDbType.NVarChar, 50);
            parr[2].Value = NoiSanXuat;
            parr[3] = new SqlParameter("@NangSuat", SqlDbType.NVarChar, 50);
            parr[3].Value = NangSuat;
            parr[4] = new SqlParameter("@LacHau", SqlDbType.Int);
            parr[4].Value = LacHau;
            parr[5] = new SqlParameter("@MaDoanhNghiep", SqlDbType.Int);
            parr[5].Value = MaDoanhNghiep;
            parr[6] = new SqlParameter("@MyImage", SqlDbType.NText);
            parr[6].Value = MyImage;

            dataUtils.ExecuteNonQuery(sqlStr, CommandType.StoredProcedure, parr);
        }
        #endregion

        #region TB_SearchByMaTB()
        public DataTable TB_SearchByMaTB()
        {   
            sqlStr = "SELECT MaThietBi, TenThietBi, NamSanXuat, NoiSanXuat, NangSuat, MaDoanhNghiep, LacHau FROM ThietBi WHERE (MaThietBi = @MaThietBi)";
            parr = new SqlParameter[1];
            parr[0] = new SqlParameter("@MaThietBi", SqlDbType.Int);
            parr[0].Value = MaThietBi;

            return dataUtils.ExecuteQuery(sqlStr, CommandType.Text, parr).Tables[0];
        }
        #endregion

        #region TB_Update()
        public void TB_Update()
        {
            sqlStr = "UPDATE ThietBi SET TenThietBi = @TenThietBi, NamSanXuat = @NamSanXuat, NoiSanXuat = @NoiSanXuat, NangSuat = @NangSuat, LacHau = @LacHau, MaDoanhNghiep = @MaDoanhNghiep WHERE MaThietBi = @MaThietBi ";
            parr = new SqlParameter[7];
            parr[0] = new SqlParameter("@TenThietBi", SqlDbType.NVarChar, 100);
            parr[0].Value = TenThietBi;
            parr[1] = new SqlParameter("@NamSanXuat", SqlDbType.VarChar, 4);
            parr[1].Value = NamSanXuat;
            parr[2] = new SqlParameter("@NoiSanXuat", SqlDbType.NVarChar, 50);
            parr[2].Value = NoiSanXuat;
            parr[3] = new SqlParameter("@NangSuat", SqlDbType.NVarChar, 50);
            parr[3].Value = NangSuat;
            parr[4] = new SqlParameter("@LacHau", SqlDbType.Int);
            parr[4].Value = LacHau;
            parr[5] = new SqlParameter("@MaDoanhNghiep", SqlDbType.Int);
            parr[5].Value = MaDoanhNghiep;
            parr[6] = new SqlParameter("@MaThietBi", SqlDbType.Int);
            parr[6].Value = MaThietBi;

            dataUtils.ExecuteNonQuery(sqlStr, CommandType.Text, parr);
        }
        #endregion        

        #endregion
        #endregion
    }
}
